// PageUtils.java
package com.example.common.util;

import org.springframework.data.domain.Page;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class PageUtils {
    
    public static <T> Map<String, Object> toPageResponse(Page<T> page) {
        Map<String, Object> response = new HashMap<>();
        response.put("content", page.getContent());
        response.put("currentPage", page.getNumber());
        response.put("totalItems", page.getTotalElements());
        response.put("totalPages", page.getTotalPages());
        return response;
    }
    
    public static <T> Map<String, Object> toPageResponse(List<T> list, int page, int size, long total) {
        Map<String, Object> response = new HashMap<>();
        response.put("content", list);
        response.put("currentPage", page);
        response.put("pageSize", size);
        response.put("totalItems", total);
        response.put("totalPages", (int) Math.ceil((double) total / size));
        return response;
    }
}